class Booking < ActiveRecord::Base
	belongs_to :event
	belongs_to :structure
	
	# structure_name getter, needed by the form as a virtual attribute.
	def structure_name
		""
	end
	
	# structure_name setter, needed by the form as a virtual attribute.
	def structure_name=(name)
		@structures = Structure.where(name: name)
		if @structures.size() != 1
			raise "Error while assigning structure to booking: structure not found with the given name or multiple structures with the same name"
		end
		
		self.structure_id = @structures[0].id
				
	end
	
	# event_name getter, needed by the form as a virtual attribute.
	def event_name
		""
	end
	
	# event_name setter, needed by the form as a virtual attribute.
	def event_name=(name)
		@events = Event.where(name: name)
		if @events.size() != 1
			raise "Error while assigning event to booking: event not found with the given name or multiple events with the same name"
		end
		
		self.event_id = @events[0].id
		 
	end
end
